<template>
    <div>
      <el-card class="ke__margin">
        <div slot="header">发件测试</div>

        <el-form @submit.prevent.native="onSubmit">
          <el-form-item label="收件地址">
            <el-input v-model="form.address" placeholder="支持多个地址，使用“,”分隔"></el-input>
          </el-form-item>

          <el-form-item label="邮件内容">
            <el-input v-model="form.content" type="textarea" rows="6"></el-input>
          </el-form-item>

          <el-form-item>
            <el-button type="primary" native-type="submit" :loading="subing">发送</el-button>

            <span class="ke__tip ke__margin-left" v-show="info">{{ info }}</span>
          </el-form-item>
        </el-form>
      </el-card>
    </div>
</template>

<script>
export default {
  name: "mailtest",
  data () {
    return {
      subing: false,
      form: {
        content: `这是一封测试的邮件`
      },
      info: ''
    }
  },
  methods: {
    onSubmit () {
      this.info = ''
      this.subing = true
      this.$http.post('admin/mailtest', this.form)
        .finally(() => this.subing = false)
        .then(result => {
          if (result.res_code === 0) {
            this.info = '邮件投递成功，如未收到可查看垃圾箱。'
          } else {
            this.info = result.res_msg
          }
        })
        .catch((res) => {
          if (res.res_msg) {
            this.info = result.res_msg
          } else {
            this.info = '服务端错误'
          }
        })
    }
  }
}
</script>

<style scoped>

</style>
